<template>
    <div class="in">
        <div class="w1">
            <p>草稿箱</p>
            <p @click="close">X</p>
        </div>
        <div class="w2">
            <div class="user-header">
                <input type="file" name="image" accept="image/*" @change='onchangeImgFun'>
                <img  alt="" :src='imgStr' class="user-header-img user-header-com">
            </div>
        </div>
        <div class="w3">
            <el-input type="text" placeholder="请输入内容" v-model="text" maxlength="15" show-word-limit></el-input>
            <div style="margin: 20px 0;"></div>
            <el-input type="textarea" placeholder="请输入合集简介" v-model="textarea" maxlength="80" show-word-limit></el-input>
        </div>
        <div class="w4">
            <div class="an1" @click="close">取消</div>
            <div class="an2" @click="thedata">确定</div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            imgStr: require('../assets/img/上传头像.png'),
            text: '',
            textarea: ''
        }
    },
    methods: {
        close() {
            this.$emit('closel', false)
        },
        onchangeImgFun (e) {
            var file = e.target.files[0]
            // console.log(file)
            // 获取图片的大小，做大小限制有用
            // let imgSize = file.size
            // console.log(imgSize)
            var _this = this
            var reader = new FileReader()
            reader.readAsDataURL(file)
            reader.onloadend = function () {
                var dataURL = reader.result
                _this.imgStr = dataURL
            }
        },
        thedata() {
            if(this.text !== '' && this.textarea !== '') {
                let obj = {
                    img: this.imgStr,
                    title: this.text,
                    Collection: this.textarea
                }
                this.$emit('parameter', obj)
                this.$emit('closel', false)
                this.imgStr = require('../assets/img/上传头像.png')
                this.text = ''
                this.textarea = ''
            }else {
                this.$message({
                    message: '不能有空值',
                    type: 'warning'
                });
            }
        }
    }
}
</script>

<style lang="less" scoped>
    .in {
        border-radius: 10px;
        width: 600px;
        height: 600px;
        background-color: white;
        position: relative;
        .w1 {
            border-bottom: 1px solid #ccc;
            display: flex;
            justify-content: space-between;
            p {
                font-weight: bolder;
                margin-left: 20px;
            }
            p:nth-last-child(1) {
                margin-right: 20px;
                color: #999;
                cursor: pointer;
            }
        }
        .w2 {
            position: relative;
            .user-header{
                display: inline-block;
                padding: 3px;
                // border: 1px solid red;
                width: 98.5%;
                display: flex;
                justify-content: center;
                img {
                    object-fit: cover;
                    width: 30%;
                }
                input {
                    // border: 1px solid red;
                    position: absolute;
                    height: 97%;
                    opacity: 0;
                }
                .tip{
                    font-size: 14px;
                    color: #666;
                    .error{
                        font-size: 12px;
                        color: tomato;
                        margin-left: 10px;
                    }
                }
            }
        }
        .w3 {
            // border: 1px solid red;
            margin-top: 16px;
            width: 90%;
            margin-left: 28px;
        }
        .w4 {
            display: flex;
            align-items: center;
            position: absolute;
            bottom: 100px;
            left: 33%;
            // justify-content: center;
            .an1 {
                border: 1px solid #999;
                width: 100px;
                height: 30px;
                display: flex;
                align-items: center;
                justify-content: center;
                // text-align: center;
                border-radius: 4px;
                padding: 2px;
                font-size: 14px;
                margin-right: 10px;
                cursor: pointer;
            }
            .an2 {
                background-color: #00c3ff;
                width: 100px;
                height: 30px;
                display: flex;
                align-items: center;
                justify-content: center;
                color: #fff;
                border-radius: 4px;
                padding: 2px;
                font-size: 14px;
                margin-right: 10px;
                cursor: pointer;
            }
        }
    }
</style>